﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Toybox.NicoSharp.Seiga.UnitTest
{
	using Seiga;
	using Primitives;

	[TestClass]
	public class Test_Seiga : AbstractTester
	{

		#region SeigaUtility


		[TestMethod]
		public void Test_GetImageFile()
		{
			string id = "2901993";
			SeigaUtility.DownloadImageFile(id, @"F:\test.png");
		}

		#endregion SeigaUtility


		#region Key

		[TestMethod]
		public void Test_GetKey()
		{
			string id = "27597";
			PostKey key = PostKey.GetKey(id, ActionType.count);

			Assert.IsNotNull(key);
		}

		#endregion Key


		#region NgClient

		[TestMethod]
		public void Test_NgClient()
		{
			NgClients list = NgClients.Get();
			Assert.IsNotNull(list);

			NgClients.NgResult result = NgClients.Add(NgType.UserId, "yuM2WWBx0pYy+ISMgqhET8i8qgQ");
			Assert.IsTrue(result.result);

			result = NgClients.Delete(NgType.UserId, "yuM2WWBx0pYy+ISMgqhET8i8qgQ");
			Assert.IsTrue(result.result);
		}

		#endregion NgClient


		#region Theme

		// http://seiga.nicovideo.jp/watch/sg49560

		[TestMethod]
		public void Test_Theme()
		{
			string id = "49560";
			Theme theme = new Theme(id);

			// Info
			Theme.Info info = theme.GetInfo();
			Assert.IsNotNull(info);

			// Data
			Theme.Data data = theme.GetData();
			Assert.IsNotNull(data);

			// Recommend
			Theme.Recommend recommend = theme.GetRecommend();
			Assert.IsNotNull(recommend);

			// CounterIncrement
			Theme.IncrementResult result = theme.CounterIncrement();
			Assert.IsTrue(result.result);
		}

		[TestMethod]
		public void Test_Theme_CommentAdd()
		{
			string id = "49560";
			Theme theme = new Theme(id);

			Theme.Data data = theme.GetData();

			string res_id = data.image_list[0].res_id;
			int frame = 1000;
			string command = null;
			string content = "0301てす2";

			Theme.CommentAddResult result = theme.CommentAdd(res_id, frame, command, content);
			Assert.IsTrue(result.created);
		}

		#endregion Theme

		#region Manga

		// http://seiga.nicovideo.jp/watch/mg52366

		[TestMethod]
		public void Test_Manga()
		{
			string id = "52366";
			Manga manga = new Manga(id);

			// Info
			Manga.Info info = manga.GetInfo();
			Assert.IsNotNull(info);

			// Data
			Manga.Data data = manga.GetData();
			Assert.IsNotNull(data);

			// Recommend
			Manga.Recommend recommend = manga.GetRecommend();
			Assert.IsNotNull(recommend);

			// Episodes
			Manga.Episodes episodes = manga.GetEpisodes();
			Assert.IsNotNull(episodes);

			// CounterIncrement
			Manga.IncrementResult result = manga.CounterIncrement();
			Assert.IsTrue(result.result);
		}

		[TestMethod]
		public void Test_Manga_CommentAdd()
		{
			string id = "52366";
			Manga manga = new Manga(id);

			// Data
			Manga.Data data = manga.GetData();
			Assert.IsNotNull(data);

			string image_id = data.image_list[0].id;
			int frame = 1000;
			string command = null;
			string content = "www";

			Manga.CommentAddResult result = manga.CommentAdd(image_id, frame, command, content);
			Assert.IsTrue(result.created);
		}

		// http://seiga.nicovideo.jp/watch/mg52075

		[TestMethod]
		public void Test_Manga_JsonCommentClient()
		{
			string id = "52075";
			Manga manga = new Manga(id);

			// Data
			Manga.Data data = manga.GetData();
			Assert.IsNotNull(data);

			// JsonCommentClient
			Manga.JsonCommentClient client = new Manga.JsonCommentClient(data.threads[0], manga.Cookies);
			var jThread = client.GetJsonThread();
			Assert.IsNotNull(jThread);

			string body = "うぽつ！";
			string mail = "コマンド 184";
			int leaf = 1;
			int vpos = 6000; // leaf * 6000 + 位置(0 ~ 6000)

			var jResult = client.GetJsonChat(jThread.thread, body, mail, leaf, vpos);
			Assert.IsNotNull(jResult);
		}

		#endregion Manga

		#region TagSlide

		// http://seiga.nicovideo.jp/watch/tag/%E3%83%86%E3%82%B9%E3%83%88

		[TestMethod]
		public void Test_TagSlide()
		{
			string tag = "テスト";
			TagSlide ts = new TagSlide(tag);

			// Info
			TagSlide.Info info = ts.GetInfo();
			Assert.IsNotNull(info);

			// Data
			TagSlide.Data data = ts.GetData();
			Assert.IsNotNull(data);

			// CounterIncrement
			TagSlide.IncrementResult result = ts.CounterIncrement(info.tag_list[0].id);
			Assert.IsTrue(result.result);
		}

		[TestMethod]
		public void Test_TagSlide_CommentAdd()
		{
			string tag = "テスト";
			TagSlide ts = new TagSlide(tag);

			// Data
			TagSlide.Data data = ts.GetData();
			Assert.IsNotNull(data);

			// CommentAdd
			int frame = 1000;
			string command = "184";
			string content = "www";

			TagSlide.CommentAddResult result = ts.CommentAdd(data.image_list[0].category_tag_id, data.image_list[0].id, frame, command, content);
			Assert.IsTrue(result.created);
		}

		#endregion TagSlide

		#region User

		// http://seiga.nicovideo.jp/user/watch/414388

		[TestMethod]
		public void Test_User()
		{
			string id = "414388";
			User user = new User(id);

			// Info
			User.Info info = user.GetInfo();
			Assert.IsNotNull(info);

			// Data
			User.Data data = user.GetData();
			Assert.IsNotNull(data);
		}

		[TestMethod]
		public void Test_User_CommentAdd()
		{
			string id = "414388";
			User user = new User(id);

			// Data
			User.Data data = user.GetData();
			Assert.IsNotNull(data);

			// CommentAdd
			int frame = 1000;
			string command = "184";
			string content = "www";

			User.CommentAddResult result = user.CommentAdd(data.image_list[0].user_id, data.image_list[0].id, frame, command, content);
			Assert.IsTrue(result.created);
		}

		#endregion User

		#region Ranking

		// ランキングプレーヤーどこー

		[TestMethod]
		public void Test_Ranking()
		{
			Ranking ranking = new Ranking(SpanType.hourly);

			// Data
			Ranking.Data data = ranking.GetData();
			Assert.IsNotNull(data);
		}

		[TestMethod]
		public void Test_Ranking_CommentAdd()
		{
			Ranking ranking = new Ranking(SpanType.hourly);

			// Data
			Ranking.Data data = ranking.GetData();
			Assert.IsNotNull(data);

			// CommentAdd
			int frame = 1000;
			string command = "184";
			string content = "www";

			Ranking.CommentAddResult result = ranking.CommentAdd(data.image_list[0].ranking_created, data.image_list[0].id, frame, command, content);
			Assert.IsTrue(result.created);
		}

		#endregion Ranking


		#region OfficialComic

		[TestMethod]
		public void Test_OfficialComic()
		{
			OfficialComic oc = new OfficialComic("1");
			OfficialComic.Info info = oc.GetInfo();
			Assert.IsNotNull(info);

			string url = oc.GetFirstUrl();
			Assert.IsTrue(url.Contains("mg"));
		}

		#endregion OfficialComic


		#region Book

		[TestMethod]
		public void Test_Book()
		{
			// ServiceStatus
			Book.ServiceStatus ss = Book.GetServiceStatus();
			Assert.IsTrue(ss.is_success);

			// UserStatus
			Book.UserStatus us = Book.GetUserStatus();
			Assert.IsTrue(us.is_success);


			Book book = new Book("1");

			// Recommendation
			Book.Recommendation recommend = book.GetRecommendation();
			Assert.IsTrue(recommend.is_success);

			// BookInfo
			Book.BookInfo info = book.GetBookInfo();
			Assert.IsTrue(info.is_success);

			// Download
			Book.Download down = book.GetDownload();
			Assert.IsTrue(down.is_success);

			// LastRead
			Book.LastRead read = book.GetLastRead();
			Assert.IsTrue(read.is_success);

		}

		#endregion Book

	}
}
